var pageinfostant=1; 

function addforminfostant()
 {
          var rownow=1;

   $("#firstaddform").append('<div class="featureclass">'+dataform['infostant']+'</div>');
   $("#pageaddfeature2").append('<div id="feature1">'+dataform['infostant1']+'</div>');
   $("#pageaddfeature3").append(dataform['infostant2']); 
   
   
    $('#pageaddfeature2 input[name="alltime[]"]').click(function() {
    
    if($(this).is(":checked"))
    {
     //$('#pageaddfeature2 input[name="openhours[]"]').attr("disabled", "disabled");
    // $('#pageaddfeature2 input[name="closehours[]"]').attr("disabled", "disabled");
         
                              
    }else
    {
   //   $('#pageaddfeature2 input[name="openhours[]"]').removeAttr("disabled");  
  //    $('#pageaddfeature2 input[name="closehours[]"]').removeAttr("disabled");  

    }
    
    });
    
    
    $('#pageaddfeature2 input[name="sameaddressprofile[]"]').click(function() {
    
    if($(this).is(":checked"))
    {
     $.post(serviceinfo+'getmyuser', { select:['address','countryid','disid','tumid','proid','code','state'] }, function(data) {
         
         //console.log(data);
         if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         
         if(data['data']['address'])$('#pageaddfeature2 textarea[name="address[]"]').val(data['data']['address']);
         
         if(data['data']['countryid'])$('#pageaddfeature2 select[name="countryid[]"]').val(data['data']['countryid']); 
       
         
         swicthcountry(data['data']['countryid'],rownow);
         
         if(data['data']['countryid']==210)
         {
         if(data['data']['proid']&&data['data']['proid']!="0")
         {

         $('#pageaddfeature2 select[name="proid[]"]').val(data['data']['proid']);
         
         var xmlRequest=getdistrict('#pageaddfeature2 select[name="disid[]"]','#pageaddfeature2 select[name="tumid[]"]',data['data']['proid'],data['data']['disid']);
         
         $('#pageaddfeature2 select[name="disid[]"]').val(data['data']['disid']);
        // $(document).ajaxComplete(function() {
        
         xmlRequest.complete(function() { 
         
         //alert("second complete"); 
         if(data['data']['disid']&&data['data']['disid']!="0") {gettumbon('#pageaddfeature2 select[name="tumid[]"]',data['data']['disid'],data['data']['tumid']);}
         
         });
        
         
     
       //  });
         
        // if(data['data']['tumid']) $('#pageaddfeature2 select[name="tumid[]"]').val(data['data']['tumid']);
         
         }
         }
         else
         {
         
         if(data['data']['state']) $('#pageaddfeature2 input[name="state[]"]').val(data['data']['state']);
         
         }
         
         
         if(data['data']['code']) $('#pageaddfeature2 input[name="code[]"]').val(data['data']['code']);
         
         
         }
       //  alert("Data Loaded: " + data);
       
       
       });

         
                              
    }
    
    });
    
    
    $('#pageaddfeature2 input[name="samecontactprofile[]"]').click(function() {
    
    if($(this).is(":checked"))
    {
    
    $.post(serviceinfo+'getmyuser', { select:['facebook','twitter','googleplus','email','website','phone','fax','etc'] }, function(data) {
    
    
           if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
          if(data['data']['facebook'])$('#pageaddfeature2 input[name="facebook[]"]').val(data['data']['facebook']); 
          if(data['data']['twitter'])$('#pageaddfeature2 input[name="twitter[]"]').val(data['data']['twitter']); 
          if(data['data']['googleplus'])$('#pageaddfeature2 input[name="googleplus[]"]').val(data['data']['googleplus']); 
          if(data['data']['email'])$('#pageaddfeature2 input[name="email[]"]').val(data['data']['email']);
          if(data['data']['website'])$('#pageaddfeature2 input[name="website[]"]').val(data['data']['website']);
          if(data['data']['phone'])$('#pageaddfeature2 input[name="phone[]"]').val(data['data']['phone']);
          if(data['data']['fax'])$('#pageaddfeature2 input[name="fax[]"]').val(data['data']['fax']);
          if(data['data']['etc'])$('#pageaddfeature2 textarea[name="etc[]"]').val(data['data']['etc']);
         
         }
    
    
    });
    
    }
    
    
    });
    
    
    
    $('#pageaddfeature2 select[name="countryid[]"]').change(function() 
    { 
     
       swicthcountry($(this).val(),rownow);
    
    });
    
    
    $('#pageaddfeature2 select[name="proid[]"]').change(function() 
    { 
    
       getdistrict('#pageaddfeature2 select[name="disid[]"]','#pageaddfeature2 select[name="tumid[]"]',$(this).val());
    
    });
    
    $('#pageaddfeature2 select[name="disid[]"]').change(function() 
    {
    gettumbon('#pageaddfeature2 select[name="tumid[]"]',$(this).val());
    
    });
    
    
    $('.wrpThemeInSt').click(function()
    {
    
              $('.wrpThemeInSt').removeClass('selectTheme');
              $(this).addClass('selectTheme');
    
    
    
    })
    
       var rowchecknow=0;
       var handler = function() {
     
    if(rowchecknow==0)
    {
    rowchecknow=1;
     $('#pageaddfeature2 .mapdata').gmap3({
          getgeoloc:{
            callback : function(latLng){
            
              if (latLng){
              
              $('#pageaddfeature2 input[name="lat[]"]').val(latLng.lat());
              $('#pageaddfeature2 input[name="lng[]"]').val(latLng.lng()); 
              
               // $('#test1-result').html('localised !');
                $(this).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#pageaddfeature2 input[name="lat[]"]').val(marker.position.lat());
                        $('#pageaddfeature2 input[name="lng[]"]').val(marker.position.lng()); 
                        
                        
                        }
                        } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
                
                
                $(this).unbind('click');
              } 
              else {

              }
            }
          }
        });
    }
        
      
     
     
     };
     
     $('#pageaddfeature2 .mapdata').bind('click', handler);
   
   
     $('#pageaddfeature2 input[name="detail[]"]').keyup(function() {
    
              if(rowchecknow==0)
              {
              rowchecknow=1;
              }
             // console.log(1);
              
             $('#pageaddfeature2 .mapdata').gmap3({
             
             
              getlatlng:{
                address:  $(this).val(),
                callback: function(results){
                
                  
                  
                  if ( !results ) return;
                  
                  
                  $(this).gmap3({
                    clear: {
                      name:["marker"],
                      last: true
                    }
                  });
                 
//console.log(results[0].geometry);
                 $('#pageaddfeature2 input[name="lat[]"]').val(results[0].geometry.location.lat());
                 $('#pageaddfeature2 input[name="lng[]"]').val(results[0].geometry.location.lng()); 
                  
                  $(this).gmap3({
                    marker:{
                      latLng:results[0].geometry.location,
                      options:{
                        draggable: true
                        },
                      events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#pageaddfeature2 input[name="lat[]"]').val(marker.position.lat());
                        $('#pageaddfeature2 input[name="lng[]"]').val(marker.position.lng()); 
                        
                        
                        }
                        }   
                        
                        
                    },
                      map:{
                        options:{
                          zoom: 15,
                          center :results[0].geometry.location
                        }
                      }
                  });
                  
                  
                  
                }
              }
              
              
              
              });  
              
     
     });
    
        
        
        $('#pageaddfeature2 .linkvdobutton').click(function() {
    
        popupvdo(7);
    
    
        });
    
           $('#pageaddfeature2 .deletevdobutton').click(function(){
   
            $('#pageaddfeature2 .vdoclass iframe').remove();
    
            });
    
    
     
   
   $(".nextBtn").click(function() { 
          if(pageinfostant==1) 
          {
          
          
            if($('#firstaddform input[name="title"]').val()=="")
    {
    alertwrongboxmsgonly('Please Input Title');
    return false;
    }
    else if($('#firstaddform textarea[name="description"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Input Description');
    return false;
    }
    else if($('#lastaddform input[name="imgmid[]"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Select Thumbnail');
    return false;
    }
          
              $(".nextBtn").addClass('btnNext');
    $(".wrpAuthUpdtAddCtnt").hide();
   $("#pageaddfeature1").hide();   
   $("#pageaddfeature2").show(); 
   $(".backBtn").show(); 
   
   
       var rownow=1;
              //      console.log($('#feature'+rownow+' input[name="lat[]"]').val());
             if($('#feature'+rownow+' input[name="lat[]"]').val()!='')
             {

             if(rowchecknow==0)
             {
          //  console.log($('#feature'+rownow+' input[name="lat[]"]').val());
             rowchecknow=1;
             
       //  $('#feature'+rownow+' .mapdata').gmap3();
              var latLng={lat:$('#feature'+rownow+' input[name="lat[]"]').val(),lng:$('#feature'+rownow+' input[name="lng[]"]').val()};
              $('#feature'+rownow+' .mapdata').gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('#feature'+rownow+' input[name="lat[]"]').val(marker.position.lat());
                        $('#feature'+rownow+' input[name="lng[]"]').val(marker.position.lng()); 
                        
                        
                        }
                        } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
              
              $('#feature'+rownow+' .mapdata').unbind('click');  
            }  
             
              
               
             }
    
    
   
   
    pageinfostant++;
          
          }else if(pageinfostant==2)
          {
          
          $("#pageaddfeature2").hide();
    $("#pageaddfeature3").show();  

    $(".nextBtn").val('Finish');
    
    
   
    
    
    pageinfostant++;
          
          }else if(pageinfostant==3)
          {
       
      saveaddfeaturedata();
       
       
       //   location.href=baseinfo+'/data/templates/shop/coffee/index.php';
          
          }
   
   });
   
   
   $(".backBtn").click(function() { 
   
          if(pageinfostant==2)
          {
          
        $(".nextBtn").removeClass('btnNext');
        $(".wrpAuthUpdtAddCtnt").show();
       $("#pageaddfeature1").show();   
       $("#pageaddfeature2").hide();
       $(".backBtn").hide(); 
       pageinfostant--;
          
          }else if(pageinfostant==3)
          {
       
       
        $("#pageaddfeature2").show();
        $("#pageaddfeature3").hide(); 
        $(".nextBtn").val('Next');
        pageinfostant--;
          
          }
   
   });
   
         
 }
 
 function stepdata(step)
{

       if(step==1)
       {
       
          if(pageinfostant==1) 
          {
          
          
          }else if(pageinfostant==2)
          {
          
          $(".backBtn").trigger( "click" );
          
          }
          else if(pageinfostant==3)
          {
          
           $(".backBtn").trigger( "click" );
           $(".backBtn").trigger( "click" );    
          
          
          }
       
       
       
       
       
       
       
       }
       else if(step==2)
       {
       
          if(pageinfostant==1) 
          {
            $(".nextBtn").trigger( "click" ); 
          
          }else if(pageinfostant==2)
          {
          
          
          
          }
          else if(pageinfostant==3)
          {
          
           $(".backBtn").trigger( "click" );
           

   
          
          
          }
       
       
       }
       else if(step==3)
       {
       
       
                  if(pageinfostant==1) 
          {
            $(".nextBtn").trigger( "click" );
            if(pageinfostant==2)
            {
             $(".nextBtn").trigger( "click" ); 
            
            } 
          
          }else if(pageinfostant==2)
          {
          
              $(".nextBtn").trigger( "click" ); 
          
          }
          else if(pageinfostant==3)
          {
          
           
           

   
          
          
          }
       
       
       }

} 

 function editforminfostant(datarow)
 {
       addforminfostant();
        var    rownow=1;
       if(datarow.alltime!="0")
    {
    $("#feature"+rownow+' input[name="alltime[]"]').trigger('click');
    }else
    {
    

    $("#feature"+rownow+' input[name="openhours[]"]').val(datarow.openhours);
    $("#feature"+rownow+' input[name="closehours[]"]').val(datarow.closehours);

    
    
    }
    
    $("#feature"+rownow+' textarea[name="infomation[]"]').val(datarow.infomation);
    
     if(datarow.sameaddressprofile!="0")
    {
    $("#feature"+rownow+' input[name="sameaddressprofile[]"]').trigger('click');
    }else
    {
    $("#feature"+rownow+' textarea[name="address[]"]').val(datarow.address);
    if(datarow.countryid)
    {
    $("#feature"+rownow+' select[name="countryid[]"]').val(datarow.countryid);  
    swicthcountry(datarow.countryid,rownow);
    
    if(datarow.countryid=="210")
    {
     if(datarow.proid!="0")
     {
     $("#feature"+rownow+' select[name="proid[]"]').val(datarow.proid);
     var xmlRequest= getdistrict("#feature"+rownow+' select[name="disid[]"]',"#feature"+rownow+' select[name="tumid[]"]',datarow.proid);     
     xmlRequest.complete(function() { 
     if(datarow.disid)
     {
     $("#feature"+rownow+' select[name="disid[]"]').val(datarow.disid);
     gettumbon("#feature"+rownow+' select[name="tumid[]"]',datarow['disid'],datarow['tumid']);
     
     }
     
     });
     
     
     
     
     
     
     
     }
    
    }
    else
    {
    
    $("#feature"+rownow+' input[name="state[]"]').val(datarow.state);
    
    
    }
    
    $("#feature"+rownow+' input[name="code[]"]').val(datarow.code);
    
    
    
    
    }
    
    
    }
    
    
    
    
    if(datarow.samecontactprofile!="0")
    {
    $("#feature"+rownow+' input[name="samecontactprofile[]"]').trigger('click');
    }else
    {
    $("#feature"+rownow+' input[name="facebook[]"]').val(datarow.facebook);
    $("#feature"+rownow+' input[name="twitter[]"]').val(datarow.twitter);
    $("#feature"+rownow+' input[name="phone[]"]').val(datarow.phone);
    $("#feature"+rownow+' input[name="googleplus[]"]').val(datarow.googleplus);
    $("#feature"+rownow+' input[name="website[]"]').val(datarow.website);
    $("#feature"+rownow+' input[name="email[]"]').val(datarow.email);
    $("#feature"+rownow+' input[name="phone[]"]').val(datarow.phone);
    $("#feature"+rownow+' input[name="fax[]"]').val(datarow.fax);
    $("#feature"+rownow+' textarea[name="etc[]"]').val(datarow.etc);
    
    }
    
    
    
     $('#feature'+rownow+' input[name="lat[]"]').val(datarow.lat);
     $('#feature'+rownow+' input[name="lng[]"]').val(datarow.lng); 
     $('#feature'+rownow+' input[name="detail[]"]').val(datarow.detail);
     
      if(datarow.url!='')
     {
     var ext = datarow.url.split('.').pop().toLowerCase();
    if(ext=="mp4") 
    {
    $('#feature'+rownow+' .vdoclass').html(' <video width="100%" height="360" controls><source src="'+datarow.url+'" type="video/mp4"></video>');
    }else
    {
    $('#feature'+rownow+' .vdoclass').html('<iframe width="640" height="360" src="'+datarow.url+'" frameborder="0" allowfullscreen></iframe>');
    }   
    
     }    
     
     $('.wrpThemeInSt').removeClass('selectTheme');  
     $('#themeid-'+datarow.tempid).addClass('selectTheme');  
         
       
 
 }

function saveforminfostant(id,plugid)    
{
var id='pageaddfeature2';    
var obj={};
var alltime,openhours,closehours,infomation,sameaddressprofile,address,countryid,proid,disid,tumid,state,code,samecontactprofile,facebook,twitter,googleplus,email,website,phone,fax,etc;

alltime=$("#"+id+' input[name="alltime[]"]').is(':checked');
if(alltime)
{
openhours="00:00";
closehours="00:00";
alltime=$("#"+id+' input[name="alltime[]"]').val();


}else
{
openhours=$("#"+id+' input[name="openhours[]"]').val();
closehours=$("#"+id+' input[name="closehours[]"]').val();
alltime=0;

}


infomation=$("#"+id+' textarea[name="infomation[]"]').val();
sameaddressprofile=$("#"+id+' input[name="sameaddressprofile[]"]').is(':checked');
if(sameaddressprofile)
{
sameaddressprofile=$("#"+id+' input[name="sameaddressprofile[]"]').val();
address="";
countryid=0;
proid=0;
disid=0;
tumid=0;
state="";
code="";
}else
{
sameaddressprofile=0;

address=$("#"+id+' textarea[name="address[]"]').val();

countryid=$("#"+id+' select[name="countryid[]"]').val();

proid=$("#"+id+' select[name="proid[]"]').val();

disid=$("#"+id+' select[name="disid[]"]').val();

tumid=$("#"+id+' select[name="tumid[]"]').val();

state=$("#"+id+' input[name="state[]"]').val();

code=$("#"+id+' input[name="code[]"]').val();

}

samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').is(':checked');
if(samecontactprofile)
{
samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').val();
facebook="";
twitter="";
googleplus="";
email="";
website="";
phone="";
fax="";
etc="";

}else
{
samecontactprofile=0;
facebook=$("#"+id+' input[name="facebook[]"]').val();
twitter=$("#"+id+' input[name="twitter[]"]').val();
googleplus=$("#"+id+' input[name="googleplus[]"]').val();
email=$("#"+id+' input[name="email[]"]').val();
website=$("#"+id+' input[name="website[]"]').val();
phone=$("#"+id+' input[name="phone[]"]').val();
fax=$("#"+id+' input[name="fax[]"]').val();
etc=$("#"+id+' textarea[name="etc[]"]').val();



}

var tempid=$("#pageaddfeature3"+' .selectTheme').attr('id').split('-').pop().toLowerCase();



if($("#"+id+' .vdoclass').html()!="")
{

url=$("#"+id+' iframe').attr("src");
if(typeof  url== "undefined")
{
url=$("#"+id+' video source').attr("src");
if(typeof  url!= "undefined")
{
var ext = url.split('.').pop().toLowerCase();
if(ext=="mp4") 
{
embed=url.split('/').pop();

}
else
{
embed="";
}
}else
{
url="";
embed="";

}

}else
{
youtube=youtube_parser(url);
if(youtube)
{
embed=youtube;
}else
{
vimeo=vimeo_parser(url);

if(vimeo)
{
embed=vimeo;

}else
{

embed="";


}

}
}

}else
{

url="";
embed="";
}



obj={plugid:plugid,url:url,embed:embed,tempid:tempid,lat:$("#"+id+' input[name="lat[]"]').val(),lng:$("#"+id+' input[name="lng[]"]').val(),detail:$("#"+id+' input[name="detail[]"]').val(),alltime:alltime,openhours:openhours,closehours:closehours,infomation:infomation,sameaddressprofile:sameaddressprofile,address:address,countryid:countryid,proid:proid,disid:disid,tumid:tumid,state:state,code:code,samecontactprofile:samecontactprofile,facebook:facebook,twitter:twitter,googleplus:googleplus,email:email,website:website,phone:phone,fax:fax,etc:etc};



return obj; 
    
    
}
